<template>
  <l-data-board
    v-if="data._isInit"
    v-bind="config"
    :label="config.title"
    :color="config.iconColor"
    :value="value"
    :des="des"
    :flagIcon="flagIcon"
    :flagIconColor="flagIconColor"
    :imgUrl="imgUrl"
    :theme="config.theme"
    :valueTitle1="config.valueTitle1"
    :valueTitle2="config.valueTitle2"
    :desnum="desnum"
    :value2="value2"
    @click.native="handleClick"
  ></l-data-board>
</template>
<script>
import { mapGetters } from "vuex";
import viewMixins from "../mixins/view";
export default {
  props: ["data", "isPreview"],
  mixins: [viewMixins()],
  data() {
    return {};
  },
  computed: {
    ...mapGetters(["modules"]),
    value() {
      const { valueKey } = this.config;
      if (valueKey && this.showData) {
        return this.showData[0][valueKey];
      } else {
        return 0;
      }
    },
    value2() {
      const { valueKey1 } = this.config;
      if (valueKey1 && this.showData) {
        return this.showData[0][valueKey1];
      } else {
        return 0;
      }
    },
    des() {
      const { subValueKey, des, theme } = this.config;
      if (theme == "3") {
        return des;
      }

      if (subValueKey && this.showData) {
        return `${des || ""} ${this.showData[0][subValueKey]}`;
      } else if (des) {
        return `${des}`;
      }
      return undefined;
    },
    desnum() {
      const { subValueKey } = this.config;
      if (subValueKey && this.showData) {
        return `${this.showData[0][subValueKey]}`;
      }
      return undefined;
    },
    flagIcon() {
      const { flagKey, theme } = this.config;

      if (flagKey && this.showData) {
        if (theme == "3") {
          return this.showData[0][flagKey] == 1
            ? "learun-icon-up-arrow"
            : "learun-icon-down-arrow";
        } else {
          return this.showData[0][flagKey] == 1
            ? "learun-icon-up-base"
            : "learun-icon-down-base";
        }
      } else {
        return "";
      }
    },
    flagIconColor() {
      const { flagKey, theme } = this.config;
      if (flagKey && this.showData) {
        if (theme == "3") {
          return this.showData[0][flagKey] == 1 ? "#FF8080" : "#12B700";
        } else {
          return this.showData[0][flagKey] == 1 ? "#3DBA84" : "#EE3B3B";
        }
      } else {
        return "";
      }
    },
    imgUrl() {
      const { imgId } = this.config;
      return imgId
        ? `${this.apiUrl}system/annexesfile/${imgId}?token=${this.token}`
        : "";
    },
  },

  mounted() {},
  methods: {
    handleClick() {
      const { moduleId, conditionInfo } = this.config;
      if (!this.isPreview && moduleId && this.$route.name == "myDesktopHome") {
        const module = this.$deepClone(
          this.modules.find((t) => t.f_ModuleId == moduleId)
        );
        if (module) {
          if (conditionInfo) {
            const code = this.$route.query.src;
            window.$ldparam = window.$ldparam || {};
            window.$ldparam[moduleId] = `${code}|${this.data.i}`;
            this.$router.$lrRouter.goto(module);
          } else {
            this.$router.$lrRouter.goto(module);
          }
        }
      }
    },
  },
};
</script>

